    //google analytics
     var _gaq = _gaq || [];
     _gaq.push(['_setAccount', 'UA-12520737-7']);
     _gaq.push(['_trackPageview']);

     (function() {
       var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
       ga.src = 'https://ssl.google-analytics.com/ga.js';
       var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
     })();

    var appSetting;

    chrome.browserAction.onClicked.addListener(function(tab){
        if(hasAppSetting()){
            var historyName = localStorage['config_name'];
            var appData = JSON.parse(localStorage["history"])[historyName]; 
            appSetting = {
                "height":appData['app_height'],
                "url":appData['app_url'],
                "config":appData['app_config'],
                "swap_type":appData['swap_type'],
                "app_id":appData['gip_app_id'],
                "frame_url":appData['frame_url'],
            };
            chrome.tabs.executeScript(null, {file:"script.js", allFrames:true});
            _gaq.push(['_trackEvent', 'browser_action', 'clicked']);
        }else{
            openOptionsPage(); 
            _gaq.push(['_trackEvent', 'app_setting_null', 'clicked']);
        }
    });

    function hasAppSetting(){
        if(localStorage['history'] && localStorage['config_name']){
            return true;
        }
        return false;
    }
    function openOptionsPage(){
        var url  = chrome.extension.getURL('options.html?is_first=1');
        chrome.tabs.create({url:url});
    }

    chrome.extension.onRequest.addListener(function(request, sender, sendResponse){
        if(request.method == "getAppSetting"){
            sendResponse({data:appSetting});
        }
    });
